package com.test.seataaccount.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.test.seataaccount.dao.AccountDao;
import com.test.seataaccount.entity.Account;
import com.test.seataaccount.service.AccountService;
import com.test.seataaccount.service.impl.AccountServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping(value = "/account")
public class AccountController {

    @Resource
    private AccountDao accountDao;

    @GetMapping(value = "/list")
    public List<Account> getList(){
        List<Account> result = accountDao.selectList(new QueryWrapper<>());
        return result;
    }

    @Resource
    private AccountServiceImpl accountService;

    /**
     * 扣减账户余额
     */
    @PostMapping("/decrease")
    public String decrease(Long userId, BigDecimal money) {
        accountService.decrease(userId, money);
        return "扣减账户余额成功！";
    }
}
